<?php
/*权限管理*/
namespace Admin\Controller;
use Think\Page;//分页类

class PasswordController extends BaseController {

    public function list_(){
        #+----------------------------------
        # * 查询权限
        #+----------------------------------
        $qx_list = M()->query("select * from adminrule group by ac order by id desc");
        
        foreach ($qx_list as $k => $v) {
            $ac = $qx_list[$k]['ac'];
            $data = M()->query("select * from adminrule where ac = '$ac'");
            $qx_list[$k]['data'] = $data;
            //查询权限
        }
        $this -> assign( "qx_list", $qx_list); 
        // print_r($qx_list);
    	#+----------------------------------
    	# * 分页
    	#+----------------------------------
        $db = M( "admingroup" );  
        $page_size = 10; //每页显示记录数  
        $record_sum = count( $db -> field('id') -> where( "1=1" ) -> select() );//记录总数  
		$Page = new Page($record_sum, $page_size);  //实例化分页类
        $list = $db-> 
                /*field( "adminuser.id,adminuser.username,groupname,logintime" ) ->  
                join( "admingroup on adminuser.group_id=admingroup.id" ) ->  */
                where( "" ) ->  
                // order( "adminuser.id " ) ->  
                limit($Page->firstRow.",".$Page->listRows) ->  
                select();  
        

        $this -> assign( "list", $list); //输出文章列表  
        $this -> assign( "page", $Page -> show_wen()); //输出分页  
        #+----------------------------------
        # * 显示页面
        #+----------------------------------
    	$this->display();
    }
    public function edit(){
        $id = $_COOKIE['wen_admin_userid'];

        $user =  M('adminuser') ->where("id=$id")->find();
        $arr = array('password'=>MD5($_GET['password_new']));

        if($user['password'] == MD5($_GET['password_old'])){
            $re = M('adminuser')->where("id=$id")->save($arr);
            if($re){
                echojson('修改成功',1);
            }else{
                echojson('修改失败',0);
            }
        }else{
            echojson('当前密码错误',0);
        }

        
        
    }
}